class UserControllerTests extends GroovyTestCase {
    void testResetPassword() {
        UserController uc = new UserController()

        // Mock login
        uc.session.LOGIN_USER = new User(username: 'xiaoming', name: 'Xiao Ming', password: 'pass123').save(validate: false)

        // Test the password is empty.
        uc.params.password = 'pass111'
        uc.resetPassword()
        assertEquals('/user/resetPassword', uc.modelAndView.viewName)

        // Test the passwords are not consistent.
        uc.params.password = 'pass111'
        uc.params.verify = 'pass123'
        uc.resetPassword()
        assertEquals('/user/resetPassword', uc.modelAndView.viewName)

        // Test success
        uc.params.password = 'pass123'
        uc.params.verify = 'pass123'
        uc.resetPassword()
        assertEquals(uc.session.LOGIN_USER.password, 'pass123')
        assertEquals('/hotel/index', uc.response.redirectedUrl)
    }
}